import { FreezePlugin } from '../../../pugins/freeze.plugin';
import { OperateBase } from '../../common/operate-base';

export class AutoWrap extends OperateBase {
    protected container: HTMLElement;
    protected plugin: FreezePlugin
    constructor() {
        super();
    }
    public getDom() {
        this.container = document.createElement('div');
        this.container.setAttribute('class', this.containerClassName);
        this.container.innerHTML=`<span class="z-tools-icon icon iconfont icon-wrap"></span>`;
        return this.container;
    }
    public selectChange(select: any, cells: any[]): void {
        
    }
    public afterDomInit(): void {
        // this.plugin = this.zTableInstance.pluginManager.getPlugin(FreezePlugin.pluginName);
        // this.zTableInstance.getHook().afterSelect.add(() => {
        //     this.toggleDisabled();
        // });
        // this.toggleDisabled();
        // let iconEle = this.container.querySelector('.icon-freeze-columns') as HTMLElement;
        // iconEle.addEventListener('click', () => {
        //     if(iconEle.classList.contains('z-table-icon-disabled')) {
        //         return;
        //     }
        //     if(this.plugin.getFreezeInfo().col !== -1) {
        //         this.plugin.cancelFreezeCol();
        //         this.toggleDisabled();
        //     } else {
        //         let select = this.plugin.getSelectInfo();
        //         if(select !== null && select.col !== -1) {
        //             this.plugin.freezeCol(select.col);
        //             this.toggleDisabled();
        //         }
        //     }
        // });
    }
    protected toggleDisabled() {
        let select = this.plugin.getSelectInfo();
        let iconEle = this.container.querySelector('.icon-freeze-columns') as HTMLElement;
        if(this.plugin.getFreezeInfo().col !== -1) {
            iconEle.classList.remove('z-table-icon-disabled');
        } else {
            if(select) {
                iconEle.classList.remove('z-table-icon-disabled');
            } else {
                iconEle.classList.add('z-table-icon-disabled');
            }
        }
    }
}